const jwt = require("jsonwebtoken")
const key = "aaaaa";

module.exports = () => {
  return async function auth(ctx, next) {
    if (ctx.request.url === '/login') {
        await next();
    } else {
        const token = ctx.request.header.authorization
        try {
            jwt.verify(token, key)
            await next();
        } catch {
            ctx.body = {
                code: 0,
                message: "权限信息被修改"
            }
        }
    }
  };
};
